# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=haskell-openafp
pkgver=1.4.3
pkgrel=1
pkgdesc='IBM AFP document format parser and generator.'
arch=('x86_64' 'aarch64')
url='http://hackage.haskell.org/package/OpenAFP'
license=('GPL')
makedepends=('ghc')
depends=('haskell-regex-compat' 'haskell-mtl' 'haskell-hashable'
         'haskell-hashtables')
install='haskell-openafp.install'
source=("http://hackage.haskell.org/packages/archive/OpenAFP/$pkgver/OpenAFP-$pkgver.tar.gz")
sha512sums=('85e6a2fe1533971f6c8d1b4af7610e067b0841827a34fad2b0c9ca17468e84c821f15bd8bb816f67d969aa8b11a4a368932ee72bac9e845ebeb10015ac1c439a')
options=('staticlibs')

build() {
  cd "OpenAFP-$pkgver"

  runhaskell Setup configure -O -p --enable-split-objs --enable-shared \
    --prefix=/usr --docdir="/usr/share/doc/haskell-openafp" \
    --libsubdir=\$compiler/site-local/\$pkgid
  runhaskell Setup build
  runhaskell Setup haddock
  runhaskell Setup register   --gen-script
  runhaskell Setup unregister --gen-script

  sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

package() {
  cd "OpenAFP-$pkgver"

  install -dm 755 "$pkgdir/usr/share/doc/ghc/html/libraries"

  install -Dm 744 register.sh "$pkgdir/usr/share/haskell/$pkgname/register.sh"
  install -m 744 unregister.sh \
    "$pkgdir/usr/share/haskell/$pkgname/unregister.sh"

  ln -s "/usr/share/doc/haskell-openafp/html" \
    "$pkgdir/usr/share/doc/ghc/html/libraries/OpenAFP"

  runhaskell Setup copy --destdir="$pkgdir"
}

